package com.examination.system.instructor.controller;

import com.examination.api.instructor.BeasControllerApi;
import com.examination.framework.model.response.QueryResponseResult;
import com.examination.system.administration.response.AddResult;
import com.examination.system.administration.response.DeleteResult;
import com.examination.system.administration.response.UpdateResult;
import com.examination.system.instructor.service.EntityRepositoryService;
import com.examination.system.instructor.service.impl.EntityRepositoryServiceImpl;
import com.examination.system.instructor.student.ext.StudentAward;
import com.examination.system.instructor.student.ext.StudentFamilyBackground;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Callable;

/**
 * @author 寇淇芮
 * @Date 2019/10/15 19:45
 */

public class BaseController< M extends EntityRepositoryService<T> ,T > implements BeasControllerApi<T> {

    @Autowired
    private M baseServerice;


    @Override
    @PutMapping("/list/{page}/{size}")
    public Callable<QueryResponseResult<T>> findList(@RequestBody(required = false) T entity,
                                                     @PathVariable("page") Integer page,
                                                     @PathVariable("size") Integer size) {
        return ()->{
            return baseServerice.findListPage(page,size,entity);
        };
    }
    @Override
    @GetMapping("/find/{id}")
    public Callable<T> findById(@PathVariable("id") String id) {
        return ()->{
            return  baseServerice.findById(id);};
    }

    @Override
    @PostMapping("/add/data")
    public Callable<AddResult<T>> addDate(@RequestBody T entity) {
        return ()->{
            return baseServerice.addEntity(entity);};
    }

    @Override
    @DeleteMapping("/delete/{id}")
    public Callable<DeleteResult<T>> deleteById(@PathVariable(name = "id") String id) {
        return ()->{
            return baseServerice.deleteById(id);};
    }

    @Override
    @PostMapping("/delete/entity")
    public Callable<DeleteResult<T>> deleteEntity(@RequestBody T entity) {
        return ()->{
            return baseServerice.deleteEentiy(entity);
        };
    }

    @Override
    @PutMapping("/update/{id}")
    public Callable<UpdateResult<T>> updateById(@RequestBody T entity,
                                                @PathVariable(name = "id") String id) {
        return ()->{
            return  baseServerice.updateById(entity,id);
        };
    }
}
